<template>
  <view class="container">
    <!-- 顶部导航区域 -->
    <view class="header">
      <view class="header-left">
        <uni-icons type="bars" size="24" @tap="toggleSidebar"></uni-icons>
      </view>
      <view class="header-center">
        <text class="header-title">智慧回收箱管理</text>
      </view>
      <view class="header-right">
        <uni-icons type="bell" size="24" class="header-icon" badge="3"></uni-icons>
        <image src="/static/logo.png" class="header-avatar"></image>
      </view>
    </view>

    <!-- 主内容区域 -->
    <view class="content">
      <!-- 核心数据概览卡片区 -->
      <view class="card-container">
        <view class="card-item card-green">
          <view class="card-header">
            <text class="card-title">今日回收量</text>
            <text class="card-unit">公斤</text>
          </view>
          <view class="card-content">
            <text class="card-value">1,245</text>
            <view class="card-trend">
              <uni-icons type="arrowup" size="14" class="trend-up"></uni-icons>
              <text class="trend-text">12.5%</text>
            </view>
          </view>
          <text class="card-compare">较昨日增长135公斤</text>
        </view>

        <view class="card-item card-blue">
          <view class="card-header">
            <text class="card-title">活跃回收箱</text>
            <text class="card-unit">台</text>
          </view>
          <view class="card-content">
            <text class="card-value">87</text>
            <view class="card-trend">
              <uni-icons type="arrowup" size="14" class="trend-up"></uni-icons>
              <text class="trend-text">3.6%</text>
            </view>
          </view>
          <text class="card-compare">较昨日新增3台</text>
        </view>

        <view class="card-item card-purple">
          <view class="card-header">
            <text class="card-title">今日收益</text>
            <text class="card-unit">元</text>
          </view>
          <view class="card-content">
            <text class="card-value">2,856</text>
            <view class="card-trend">
              <uni-icons type="arrowup" size="14" class="trend-up"></uni-icons>
              <text class="trend-text">8.3%</text>
            </view>
          </view>
          <text class="card-compare">较昨日增长218元</text>
        </view>

        <view class="card-item card-orange">
          <view class="card-header">
            <text class="card-title">用户活跃度</text>
            <text class="card-unit">人</text>
          </view>
          <view class="card-content">
            <text class="card-value">532</text>
            <view class="card-trend">
              <uni-icons type="arrowdown" size="14" class="trend-down"></uni-icons>
              <text class="trend-text">2.1%</text>
            </view>
          </view>
          <text class="card-compare">较昨日减少11人</text>
        </view>
      </view>

      <!-- 回收箱状态监控区域 -->
      <view class="status-container">
        <view class="section-title">回收箱状态监控</view>
        <view class="status-content">
          <view class="status-chart">
            <canvas canvas-id="statusChart" class="status-canvas"></canvas>
          </view>
          <view class="status-list">
            <view class="status-item">
              <view class="status-dot status-normal"></view>
              <text class="status-text">正常运行</text>
              <text class="status-count">87</text>
            </view>
            <view class="status-item">
              <view class="status-dot status-warning"></view>
              <text class="status-text">需要清理</text>
              <text class="status-count">12</text>
            </view>
            <view class="status-item">
              <view class="status-dot status-error"></view>
              <text class="status-text">故障维修</text>
              <text class="status-count">5</text>
            </view>
            <view class="status-item">
              <view class="status-dot status-offline"></view>
              <text class="status-text">离线状态</text>
              <text class="status-count">3</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 实时数据图表区域 -->
      <view class="chart-container">
        <view class="section-title">实时数据图表</view>
        <view class="chart-tabs">
          <uni-segmented-control :current="activeTab" :values="['今日', '本周', '本月']" @clickItem="onTabChange" active-color="#1AAD19"></uni-segmented-control>
        </view>
        <view class="chart-content">
          <view class="chart-item">
            <text class="chart-title">7天回收量趋势</text>
            <canvas canvas-id="trendChart" class="trend-canvas"></canvas>
          </view>
          <view class="chart-item">
            <text class="chart-title">回收物品分类占比</text>
            <canvas canvas-id="categoryChart" class="category-canvas"></canvas>
          </view>
        </view>
      </view>

      <!-- 快捷操作区域 -->
      <view class="quick-actions">
        <view class="section-title">快捷操作</view>
        <view class="actions-grid">
          <view class="action-item">
            <view class="action-icon action-blue">
              <uni-icons type="settings" size="24"></uni-icons>
            </view>
            <text class="action-text">设备管理</text>
          </view>
          <view class="action-item">
            <view class="action-icon action-green">
              <uni-icons type="person" size="24"></uni-icons>
            </view>
            <text class="action-text">用户管理</text>
          </view>
          <view class="action-item">
            <view class="action-icon action-yellow">
              <uni-icons type="creditcard" size="24"></uni-icons>
            </view>
            <text class="action-text">收益统计</text>
          </view>
          <view class="action-item">
            <view class="action-icon action-red">
              <uni-icons type="repair" size="24"></uni-icons>
            </view>
            <text class="action-text">维护派单</text>
          </view>
          <view class="action-item">
            <view class="action-icon action-purple">
              <uni-icons type="stats" size="24"></uni-icons>
            </view>
            <text class="action-text">数据报表</text>
          </view>
          <view class="action-item">
            <view class="action-icon action-gray">
              <uni-icons type="setting" size="24"></uni-icons>
            </view>
            <text class="action-text">系统设置</text>
          </view>
        </view>
      </view>

      <!-- 异常提醒区域 -->
      <view class="alerts-container">
        <view class="section-title">异常提醒</view>
        <view class="alerts-list">
          <view class="alert-item">
            <view class="alert-icon alert-error"></view>
            <view class="alert-content">
              <text class="alert-title">设备故障提醒</text>
              <text class="alert-detail">中心广场A-01号回收箱出现故障</text>
              <text class="alert-time">2023-09-28 08:30</text>
            </view>
            <button class="alert-btn" size="mini">处理</button>
          </view>
          <view class="alert-item">
            <view class="alert-icon alert-warning"></view>
            <view class="alert-content">
              <text class="alert-title">满箱提醒</text>
              <text class="alert-detail">科技园B-05号回收箱即将满箱</text>
              <text class="alert-time">2023-09-28 09:45</text>
            </view>
            <button class="alert-btn" size="mini">处理</button>
          </view>
          <view class="alert-item">
            <view class="alert-icon alert-info"></view>
            <view class="alert-content">
              <text class="alert-title">维护到期提醒</text>
              <text class="alert-detail">东区C-03号回收箱需要定期维护</text>
              <text class="alert-time">2023-09-28 10:15</text>
            </view>
            <button class="alert-btn" size="mini">处理</button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        activeTab: 0,
        statusChart: null,
        trendChart: null,
        categoryChart: null
      }
    },
    onLoad() {
      this.initCharts();
    },
    methods: {
      toggleSidebar() {
        // 侧边栏切换逻辑
        console.log('切换侧边栏');
      },
      onTabChange(e) {
        this.activeTab = e.current;
        this.updateTrendChart();
      },
      initCharts() {
        // 初始化回收箱状态环形图
        this.initStatusChart();
        // 初始化7天回收量趋势图
        this.initTrendChart();
        // 初始化回收物品分类饼图
        this.initCategoryChart();
      },
      initStatusChart() {
        // 模拟环形图数据
        // 实际项目中应使用真实的图表库如echarts-for-weixin
        console.log('初始化回收箱状态环形图');
      },
      initTrendChart() {
        // 模拟折线图数据
        // 实际项目中应使用真实的图表库如echarts-for-weixin
        console.log('初始化7天回收量趋势图');
      },
      initCategoryChart() {
        // 模拟饼图数据
        // 实际项目中应使用真实的图表库如echarts-for-weixin
        console.log('初始化回收物品分类饼图');
      },
      updateTrendChart() {
        // 根据选中的时间范围更新趋势图
        console.log('更新趋势图，当前选中：', this.activeTab);
      }
    }
  }
</script>

<style scoped>
  .container {
    width: 100%;
    min-height: 100vh;
    background-color: #f5f5f5;
    padding-bottom: 60px; /* 添加底部内边距，确保内容不被底部导航栏遮挡 */
    box-sizing: border-box;
  }

  /* 顶部导航区域 */
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 44px;
    background-color: #1AAD19;
    color: #ffffff;
  }
  .header-left {
    width: 40px;
  }
  .header-center {
    flex: 1;
    text-align: center;
  }
  .header-title {
    font-size: 18px;
    font-weight: bold;
  }
  .header-right {
    display: flex;
    align-items: center;
  }
  .header-icon {
    margin-right: 16px;
    color: #ffffff;
  }
  .header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #ffffff;
  }

  /* 主内容区域 */
  .content {
    padding: 16px;
  }

  /* 核心数据概览卡片区 */
  .card-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
  }
  .card-item {
    padding: 16px;
    border-radius: 8px;
    color: #ffffff;
  }
  .card-green {
    background: linear-gradient(135deg, #1AAD19, #36D399);
  }
  .card-blue {
    background: linear-gradient(135deg, #1890FF, #40A9FF);
  }
  .card-purple {
    background: linear-gradient(135deg, #722ED1, #9254DE);
  }
  .card-orange {
    background: linear-gradient(135deg, #FA8C16, #FFC53D);
  }
  .card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
  }
  .card-title {
    font-size: 14px;
    opacity: 0.8;
  }
  .card-unit {
    font-size: 12px;
    opacity: 0.7;
  }
  .card-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 8px;
  }
  .card-value {
    font-size: 24px;
    font-weight: bold;
  }
  .card-trend {
    display: flex;
    align-items: center;
  }
  .trend-up {
    color: #ffffff;
    margin-right: 2px;
  }
  .trend-down {
    color: #ffffff;
    margin-right: 2px;
  }
  .trend-text {
    font-size: 12px;
  }
  .card-compare {
    font-size: 12px;
    opacity: 0.7;
  }

  /* 回收箱状态监控区域 */
  .status-container {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
  }
  .section-title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 16px;
    color: #333333;
  }
  .status-content {
    display: flex;
    align-items: center;
  }
  .status-chart {
    width: 120px;
    height: 120px;
    margin-right: 20px;
  }
  .status-canvas {
    width: 100%;
    height: 100%;
  }
  .status-list {
    flex: 1;
  }
  .status-item {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
  }
  .status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
  }
  .status-normal {
    background-color: #52C41A;
  }
  .status-warning {
    background-color: #FAAD14;
  }
  .status-error {
    background-color: #F5222D;
  }
  .status-offline {
    background-color: #8C8C8C;
  }
  .status-text {
    flex: 1;
    font-size: 14px;
    color: #333333;
  }
  .status-count {
    font-size: 14px;
    font-weight: bold;
    color: #333333;
  }

  /* 实时数据图表区域 */
  .chart-container {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
  }
  .chart-tabs {
    margin-bottom: 16px;
  }
  .chart-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  .chart-item {
    background-color: #fafafa;
    border-radius: 6px;
    padding: 12px;
  }
  .chart-title {
    display: block;
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 12px;
    color: #333333;
  }
  .trend-canvas {
    width: 100%;
    height: 180px;
  }
  .category-canvas {
    width: 100%;
    height: 180px;
  }

  /* 快捷操作区域 */
  .quick-actions {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
  }
  .actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
  .action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .action-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    color: #ffffff;
  }
  .action-blue {
    background-color: #1890FF;
  }
  .action-green {
    background-color: #52C41A;
  }
  .action-yellow {
    background-color: #FAAD14;
  }
  .action-red {
    background-color: #F5222D;
  }
  .action-purple {
    background-color: #722ED1;
  }
  .action-gray {
    background-color: #8C8C8C;
  }
  .action-text {
    font-size: 14px;
    color: #333333;
  }

  /* 异常提醒区域 */
  .alerts-container {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
  }
  .alerts-list {
    
  }
  .alert-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
  }
  .alert-item:last-child {
    border-bottom: none;
  }
  .alert-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
  }
  .alert-error {
    background-color: #FFF2F0;
    border: 1px solid #FFCCC7;
  }
  .alert-warning {
    background-color: #FFFBE6;
    border: 1px solid #FFE58F;
  }
  .alert-info {
    background-color: #E6F7FF;
    border: 1px solid #91D5FF;
  }
  .alert-content {
    flex: 1;
  }
  .alert-title {
    display: block;
    font-size: 14px;
    font-weight: bold;
    color: #333333;
    margin-bottom: 4px;
  }
  .alert-detail {
    display: block;
    font-size: 13px;
    color: #666666;
    margin-bottom: 4px;
  }
  .alert-time {
    display: block;
    font-size: 12px;
    color: #999999;
  }
  .alert-btn {
    background-color: #1AAD19;
    color: #ffffff;
    font-size: 12px;
    height: 28px;
    line-height: 28px;
    margin-top: 6px;
  }
</style>
